// 禁止长按调用系统
// window.addEventListener('contextmenu', function(e){  
//     e.preventDefault();  
// });


// 获取地址栏
export function _getParames(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
}
export function getParames(name) {
    // console.log(location)
    var after = window.location.hash.split("?")[1];
    if(after){
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = after.match(reg);
        if (r != null) return decodeURIComponent(r[2]);
        return null;
    }
}

// 遍历删除
// function listRemove(_arr,obj,val){
//     for (var i = 0; i < _arr.length; i++) {
//         if (_arr[i].obj == val){
//             _arr.splice(i, 1);
//         }
//     }
// };

// export function bodyHidden(){
//     document.body.style.overflow='hidden';
// }
// export function bodyAuto(){
//     document.body.style.overflow='auto';
// }

// export function touchDefault(event){
   
//     event.preventDefault();	
// }
// //禁用手机默认的触屏滚动行为
// export function touchFalse(){
    
//     document.addEventListener('touchmove',touchDefault, { passive: false });
// }
// //恢复手机默认的触屏滚动行为
// export function touchTrue(){
   
//     document.removeEventListener('touchmove',touchDefault, { passive: false });
// }

// 提示弹层
export function alertMask(obj,text){
    // touchFalse()
    obj.alertMaskShow=true;
    obj.alertMaskText=text;
    setTimeout(()=>{           //低版本系统不支持ES6，that=this
        // touchTrue()
        obj.alertMaskShow=false;    
    },1500);
}

// 是否存在该方法
export function hasFunction(funName,resFun,obj){
    let isFunction = false;
    try{
        isFunction = typeof(eval(funName))=="function";
    }catch(e){}
    // return isFunction
    if(isFunction){
        resFun()
    }else{
        alertMask(obj,'<p>您的版本过低</p><p>请前往应用市场升级您的快乐学堂App</p>') 
    }
}

//判断设备
export function iosSystem() {
    let iosSys=false;
    let uA = navigator.userAgent;
    let isAndroid = uA.indexOf('Android') > -1 || uA.indexOf('Adr') > -1; //android终端
    let isiOS = !!uA.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
    if(!isAndroid){  //ios终端
        iosSys=true;
    }
    return iosSys;
}

//图片加载
export function imgLoad(img, callback) {
    let timer = setInterval(()=> {
        if (img.complete) {
        callback(img)
        clearInterval(timer)
        }
    }, 50)
}

//随机字符串
export function randomRange(min, max){
    var randomStr = "",
        range = (max ? Math.round(Math.random() * (max-min)) + min : min),
        charStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    for(let i=0; i<range; i++){
        let index = Math.round(Math.random() * (charStr.length-1));
        randomStr += charStr.substring(index,index+1);
    }
    return randomStr;
}

// 时间输出
export function getTimeStr(time){
    let year=time.getFullYear();
    let month=time.getMonth()+1;
    let date=time.getDate();
    let timeString=time.toTimeString().substring(0,5);
    let dayTimeString=year+'年'+month+'月'+date+'日';
    let dayTimeStr=year+'-'+month+'-'+date+' '+timeString;
    return dayTimeString
}